package ducna.misscall.comon.fragment;

/**
 * @author DUCNA
 */
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import ducna.alozo.misscall.R;
import ducna.misscall.screen.misscall.MissCallFragment;
import ducna.misscall.utils.Logger;

public abstract class BaseFragment extends Fragment {
	private String TAG = BaseFragment.class.getSimpleName();

	private ImageView actionBarLeft;
	private TextView actionBarTitle;

	private RelativeLayout header;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		header = (RelativeLayout) getActivity().getLayoutInflater().inflate(R.layout.header, null);
		
		actionBarLeft = (ImageView)  header.findViewById(R.id.imageViewBack);
		actionBarTitle = (TextView) header.findViewById(R.id.textViewTitle);
	}
	
	protected void setActionBarTitle(int titleId){
		actionBarTitle.setText(getString(titleId));
	}
	
	protected void setActionBarLeft(OnClickListener listener){
		actionBarLeft.setOnClickListener(listener);
	}
	
	protected void addFragment(Fragment fragment, int idOfContainer) {
		Fragment f = getActivity().getSupportFragmentManager().findFragmentById(android.R.id.content);
        if (f == null) {
        	getActivity().getSupportFragmentManager().beginTransaction().add(idOfContainer, fragment).commit();
        } else {
        	getActivity().getSupportFragmentManager().beginTransaction().replace(idOfContainer, fragment).commit();
        }
	}
}
